/*
 * Copyright (c) 2017,安徽皖通科技股份有限公司 All rights reserved.
 */

package com.wttech.dzzf.process.service.transfer;

import com.wtkj.vo.dzzf.base.kfwd.AccountOpt;
import com.wttech.dzzf.process.dao.DataTransferDao;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 数据迁移-业务账户开户记录校验
 * @author MaShibo
 * @date 2017/11/6.
 */
@Service
public class AccountOptCheckService {

    private static final Logger ERRORINFO = DataTransferService.ERRORINFO;

    @Resource
    private DataTransferDao dataTransferDao;

    /**
     * 默认开户操作编号
     */
    static final String DEFAULT_OPTTYPE = "1010";

    void analyseAccountOpt(AccountOpt accountOpt){

        checkAccountOptIsValid(accountOpt);

        String optId = accountOpt.getOptId();
        Integer idNum = dataTransferDao.queryOptId(optId);
        if (idNum != null && idNum >= 1){
            ERRORINFO.info("开户操作记录{}，ID【{}】已存在", optId, optId);
        }

        String tradeNo = accountOpt.getTradeNo();
        Integer tradeNoNum = dataTransferDao.queryTradeNo(tradeNo);
        if (tradeNoNum != null && tradeNoNum >= 1){
            ERRORINFO.info("开户操作记录{}，交易流水号【{}】已存在", optId, tradeNo);
        }

    }

    private void checkAccountOptIsValid(AccountOpt accountOpt){

        String optId = accountOpt.getOptId();
        //操作类型
        String optType = accountOpt.getOptType();
        if (!StringUtils.equalsIgnoreCase(optType, DEFAULT_OPTTYPE)){
            ERRORINFO.info("开户操作记录{}，操作类型【{}】错误", optId, optType);
        }

    }

}
